﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MSBTC.Model;

namespace MSBTC.WinForms
{
    public partial class LaborerListForm : Form
    {
        private string Datamanip;
        private int rowselect;
        MDIParent mdipar = new MDIParent();
        PMSContext dbcontext = new PMSContext();
        Labor dbcus = new Labor();

        public LaborerListForm()
        {
            InitializeComponent();
        }

        private void LaborerListForm_Load(object sender, EventArgs e)
        {
            RefreshDB();
        }
        
        #region functions
        private void RefreshDB()
        {
            var lbr = (from l in dbcontext.Labors
                       select l).ToList();

            LVLbrListInfo.Items.Clear();
            if (lbr != null)
            {

                foreach (var sqlLbr in lbr)
                {
                    ListViewItem lvitems = LVLbrListInfo.Items.Add(sqlLbr.Labourid_PK.ToString());
                    lvitems.SubItems.Add(sqlLbr.Labour_Name.ToString());
                    lvitems.SubItems.Add(sqlLbr.Position.ToString());
                    lvitems.SubItems.Add(sqlLbr.Rate.ToString());
                    lvitems.SubItems.Add(sqlLbr.NumOf_Days.ToString());
                    lvitems.SubItems.Add(sqlLbr.Total.ToString());
                    lvitems.SubItems.Add(sqlLbr.Cash_Advance.ToString());
                    lvitems.SubItems.Add(sqlLbr.Net_Paid.ToString());


                }
            }
            this.Refresh();
        }



        private void DisableFields()
        {
            //txtCname.Enabled = false;
            //txtAddr.Enabled = false;
            //txtCity.Enabled = false;
            //txtDesc.Enabled = false;
            //txtEadd.Enabled = false;
            //txtCnum.Enabled = false;

        }

        private void EnableFields()
        {
            //txtCname.Enabled = true;
            //txtAddr.Enabled = true;
            //txtCity.Enabled = true;
            //txtDesc.Enabled = true;
            //txtEadd.Enabled = true;
            //txtCnum.Enabled = true;

        }

        private void RefreshFields()
        {
            DisableFields();
            RefreshDB();

            //btnCNew.Enabled = true;
            //btnCDel.Enabled = false;
            //btnCEdit.Enabled = false;
            //btnClear.Enabled = true;
            //btnCSave.Enabled = false;
        }
        #endregion

        private void txtSearch_TextChanged(object sender, EventArgs e)
        {
            var lbr = (from l in dbcontext.Labors
                       where l.Labour_Name.Contains(txtSearch.Text)
                       select l).ToList();

            LVLbrListInfo.Items.Clear();
            if (lbr != null)
            {

                foreach (var sqlLbr in lbr)
                {
                    ListViewItem lvitems = LVLbrListInfo.Items.Add(sqlLbr.Labourid_PK.ToString());
                    lvitems.SubItems.Add(sqlLbr.Labour_Name.ToString());
                    lvitems.SubItems.Add(sqlLbr.Position.ToString());
                    lvitems.SubItems.Add(sqlLbr.Rate.ToString());
                    lvitems.SubItems.Add(sqlLbr.NumOf_Days.ToString());
                    lvitems.SubItems.Add(sqlLbr.OT_Amount.ToString());
                    lvitems.SubItems.Add(sqlLbr.Amount_Week.ToString());
                    lvitems.SubItems.Add(sqlLbr.Total.ToString());
                    lvitems.SubItems.Add(sqlLbr.Cash_Advance.ToString());
                    lvitems.SubItems.Add(sqlLbr.Net_Paid.ToString());


                }
                
                if (txtSearch.Text == "")
                {
                    RefreshDB();
                }
            }
        }
    }
}
